package com.sptechsys.m2ejb32weblogic.ejb3.client;

import java.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import com.sptechsys.m2ejb32weblogic.ejb3.stateless.HelloWorld;

/**
 * 
 * Class HelloWorldClient<br>
 * 
 * @author <a href="mailto:info[at]sptechsys">SPTECHSYS</a>
 * @version 1.0
 */
public class HelloWorldClient {

	private static HelloWorld helloWorld;

	public static void main(String[] args) {
		try

		{
			// The environment properties are needed when you are try to access
			// weblogic from one application outside the container.
			Hashtable<String, String> env = new Hashtable<String, String>();
			env.put(Context.INITIAL_CONTEXT_FACTORY,
					"weblogic.jndi.WLInitialContextFactory");
			env.put(Context.SECURITY_PRINCIPAL, "weblogic");
			env.put(Context.SECURITY_CREDENTIALS, "weblogic123");
			env.put(Context.PROVIDER_URL, "t3://localhost:7001");
			Context ctx = new InitialContext(env);

			System.out.println("Initial Context created");
			// Find the remote interface
			helloWorld = (HelloWorld) ctx
					.lookup("HelloWorld#com.sptechsys.m2ejb32weblogic.ejb3.stateless.HelloWorld");
			System.out.println("lookup successful");
			System.out.println("Calling EJB method . . .");
			// Call the service method
			String output = helloWorld.sayHello("DemoEJB3");
			System.out.println("Output :" + output);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
